﻿using CanalService.EFCore;
using CanalService.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
using System.Data;

namespace CanalService.Services
{
    /// <summary>
    /// 
    /// </summary>
    public class UserInfoRepository : IUserInfoRepository
    {
        private readonly ProjectEFCoreContext _dbContext;

        public UserInfoRepository(ProjectEFCoreContext dbContext)
        {
            _dbContext = dbContext;
        }

        public async Task<UserInfo> GetUserInfoAsync()
        {
            var list = await _dbContext.UserInfo.ToListAsync();
            return list.FirstOrDefault();

        }

        /// <summary>
        /// 写入数据
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public async Task<bool> InsertUserInfoAsync(UserInfo userInfo)
        {
           _dbContext.UserInfo.Add(userInfo);
            var result = await _dbContext.SaveChangesAsync();
            return result > 0;
        }


    }
}
